package com.xyzq.hs.util;

import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

public class LoggerFactory {
	private static Map<String,Integer> levelMap=new HashMap<String,Integer>();
	
	private static Properties levelConf=new Properties();
	
	static{
		levelMap.put("ALL",LoggerLevel.ALL);
		levelMap.put("DEBUG",LoggerLevel.DEBUG);
		levelMap.put("INFO",LoggerLevel.INFO);
		levelMap.put("WARN",LoggerLevel.WARN);
		levelMap.put("ERROR",LoggerLevel.ERROR);
		levelMap.put("FATAL",LoggerLevel.FATAL);
		levelMap.put("OFF",LoggerLevel.OFF);
		
		InputStream in=PropertiesUtil.class.getClassLoader()
				.getResourceAsStream("log4ts.properties");
		try {
			levelConf.load(in);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	public static Logger getLogger(Class<?> clazz){
		String key = clazz.getName();
		key="log4ts.logger."+key;
		Object object = levelConf.get(key);
		if(object==null){
			return new LoggerImpl();
		}else{
			String levelName = object.toString().toUpperCase();
			Integer level = levelMap.get(levelName);
			return new LoggerImpl(level);
		}
	}
}
